<style>
.layui-form-switch {
    min-width: 55px;
}
.layui-form-checkbox {height: 22px;line-height: 20px;margin-right: 0px;padding-right: 20px;}
.layui-form-checkbox i {right: 3px;width: 20px;font-size: 16px;top: 2px;}

</style>
<div class="ibox">
        <div class="ibox-title">
        <h5>用户管理</h5>
        
<div class="nowrap pull-right" style="margin-top:10px">
    <button data-modal='user/edit' data-title="添加用户" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加用户</button>
    <button data-update data-field='is_del' data-value='1' data-action='user/del' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除用户</button>
</div>

    </div>
        <div class="ibox-content fadeInUp animated">
                
<!-- 表单搜索 开始 -->
<form class="animated form-search " action="user/index" onsubmit="return false" method="get" data-search>

    <div class="row">
        <div class="col-xs-3">
            <div class="form-group">
                <input type="text" name="uname" value="${search_uname!''}" placeholder="用户名"
                       class="input-sm form-control">
            </div>
        </div>

        <div class="col-xs-3">
            <div class="form-group">
                <input type="text" name="login" value="${search_login!''}" placeholder="手机号"
                       class="input-sm form-control">
            </div>
        </div>

        <div class="col-xs-1">
            <div class="form-group">
            	<input type='hidden' value='1' name='page'/>
                <button type="submit" class="btn btn-sm btn-white"><i class="fa fa-search"></i> 搜索</button>
            </div>
        </div>
    </div>
</form>
<!-- 表单搜索 结束 -->

<form onsubmit="return false;" data-auto="" method="POST" class="layui-form">
    <input type="hidden" value="resort" name="action"/>
    <table class="table table-hover">
        <thead>
            <tr>
                <th class='list-table-check-td'>
                    <input data-none-auto="" data-check-target='.list-check-box' type='checkbox'  lay-filter="checkAll"/>
                </th>
                 <th class='text-center'>ID</th>
                <th class='text-left'>用户账号</th>
                <th class='text-center'>手机号</th>
                <th class='text-left'>电子邮箱</th>
                <th class='text-right'>登录次数</th>
                <th class='text-center'>最后登录</th>
                <th class='text-center'>启用状态</th>
                <th class='text-center'>操作</th>
            </tr>
        </thead>
        <tbody>
        <#list page.data as user>
       
                        <tr>
                <td class='list-table-check-td'>
                    <input class="list-check-box" value='${user.id?c}' type='checkbox'  lay-filter="checkOne"/>
                </td>
                 <td class='text-center'>${user.id?c}</td>
                <td class='text-left'>${user.username!""}</td>
                <td class='text-center'>${user.login!""}</td>
                <td class='text-left'><span style='color:#ccc'>${user.email!""}</span></td>
                <td class='text-right'>${user.loginNum}</td>
                <td class='text-center'><span style='color:#ccc'>${user.lastLogin!"从未登录"}</span></td>
                <td class='text-center'>
                 <input type="checkbox" value="${user.id?c}" ${user.status?string("checked","")}  lay-skin="switch"  lay-filter="status" lay-text="启用|停用"/>
                 
                </td>
                <td class='text-center nowrap'>
                    <span class="text-explode">|</span>
                    <a data-modal='user/edit?uid=${user.id?c}' href="javascript:void(0)">编辑</a>
                    <span class="text-explode">|</span>
                    <a data-modal='user/auth?uid=${user.id?c}' href="javascript:void(0)">授权</a>
                    <span class="text-explode">|</span>
                    <a data-modal='user/editPass?uid=${user.id?c}' href="javascript:void(0)">密码</a>
                    <span class="text-explode">|</span>
                    <a data-action='user/del' data-update="${user.id?c}" href="javascript:void(0)">删除</a>
                </td>
            </tr>
            </#list>
                    </tbody>
    </table>
 <p>
 
 <ul class="pagination pull-right"> 
 
 <#import "/common/page.html" as p> 
  <@p.page data=page url="user/index" search_param=search_param />
 </ul>
 
 </p>
 
 
 </form>
    </div>  
</div>
<script>
layui.use('form', function(){
	  var form = layui.form(); 
	  form.render();
	  form.on('switch(status)', function(data){
  		var y=this.checked;
  		var id=this.value;
  	
  		$.get("user/updateStatus", {status:(y?1:0),id:id}, function(data1, textStatus, req) {
  			res=new Object();
  			res.code = 1;
			res.wait = 3;
			res.msg = (y?'启用':'停用')+'用户操作成功！';
  			$.msg.auto(res, 1);
  			/* layer.msg((y?'启用':'停用')+'角色操作成功！', {
  			      offset: '16px',
  			      icon:'1'
  			    });
  			*/
  		});
	  });
	  
	  form.on('checkbox(checkAll)', function(data){
	        if(data.elem.checked){
	          $("input[lay-filter='checkOne']").prop('checked',true);
	        }else{
	          $("input[lay-filter='checkOne']").prop('checked',false);
	        }
	        form.render('checkbox');
	      });  

	      form.on('checkbox(checkOne)', function(data){
	        var is_check = true;
	        if(data.elem.checked){
	          $("input[lay-filter='checkOne']").each(function(){
	            if(!$(this).prop('checked')){ is_check = false; }
	          });
	          if(is_check){
	            $("input[lay-filter='checkAll']").prop('checked',true);
	          }
	        }else{
	          $("input[lay-filter='checkAll']").prop('checked',false);
	        } 
	        form.render('checkbox');
	      });
	}); 

</script>
